<template>
  <el-container style = "max-height: 100%">
    <el-header class = "star-horse-header  ">
      <app-header :is-collapse = "!isCollapse" @collopseOperation = "collopseOperation"/>
    </el-header>
    <el-container style = "height: calc( 100vh - 105px); padding-bottom:1cm; ">
      <el-aside :width = "!this.outerIsCollapse?'64px':'200px'"
                class = "star-horse-left animate__animated animate__bounceInLeft"
                @mouseover = "mouseOver"
                @mouseout = "mouseOut"
      >
        <app-left :is-collapse = "!isCollapse" :leftMenuDatas = "leftMenuDatas"/>
      </el-aside>
      <el-main class = "star-horse-main  animate__animated animate__bounceInUp">
        <div class = "nav_area ">
          <div class = "toolbar">
            <el-tag @click = "changeTab(-1)" class = "toolItem">
              <user-icon icon = "angle-double-left"/>
            </el-tag>
            <el-tag :class = "{active:$route.path===item.path}"
                    :closable = "item.path!='/home'"
                    :disable-transitions = "false"
                    :key = "index"
                    @click = "redirect(item)"
                    @close = "closeTab(item)"
                    class = "toolItem"
                    effect = "plain"
                    type = "info"
                    v-for = "(item,index) in getNavData"
            >
              <span class = "dot" v-if = "$route.path===item.path"></span>
              <el-tooltip :content = "item.name" placement = "top">{{ item.name }}</el-tooltip>
            </el-tag>
            <div style = "position: absolute;right: 0">
              <el-tag @click = "changeTab(1)" class = "toolItem">
                <user-icon icon = "angle-double-right"/>
              </el-tag>
              <el-dropdown hide-on-click = "false" placement = "bottom" trigger = "hover">
                <span class = "el-tag el-tag--light toolItem">菜单列表</span>
                <template #dropdown>
                  <el-dropdown-menu>
                    <el-dropdown-item :class = "{active:$route.path===item.path}"
                                      :divided = "true"
                                      :key = "index"
                                      :title = "item.name"
                                      @click = "redirect(item)"
                                      @close = "closeTab(item)"
                                      class = "clearfix"
                                      v-for = "(item,index) in getNavData"
                    >
                      <span class = "dot" v-if = "$route.path===item.path"></span>
                      {{ item.name }}
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </template>
              </el-dropdown>
            </div>
          </div>
        </div>
        <router-view v-slot = "{Component}" class = "animate__animated animate__fadeIn">
          <transition name = "solid">
            <keep-alive :include = "getViewCache">
              <component :is = "Component"/>
            </keep-alive>
          </transition>
        </router-view>
      </el-main>
    </el-container>
  </el-container>
  <el-backtop :bottom = "100">
    <div
        class = "page-up">
      UP
    </div>
  </el-backtop>
</template>

<script>
import {mapGetters} from "vuex";
import AppHeader from "./AppHeader";
import AppLeft from "./AppLeft";
import {createRouterAndMenuList, permissionMenus} from "../api/star_horse";
import {getCurrentInstance, provide} from "vue";

export default {
  name: 'Dashboard',
  components: {AppLeft, AppHeader},
  setup() {
    const {proxy} = getCurrentInstance();
    const loadMenuFun = (data) => {
      proxy.loadMenus(data);
    }
    provide("loadMenu", loadMenuFun);
  },
  data() {
    return {
      isCollapse: true,
      outerIsCollapse: true,
      leftMenuDatas: []
    }
  },
  created() {
    let path = "/home";
    let name = "首页";
    this.$store.dispatch("commitNavBar", {name, path, componentName: "Index"});
    this.leftMenuDatas = this.getPermissionMenus;
  },
  methods: {
    mouseOver() {
      $(".star-horse-left").addClass('show-scroll-bar');
    },
    mouseOut() {
      $(".star-horse-left").removeClass('show-scroll-bar');
    },
    loadMenus(sysemId) {
      let that = this;
      permissionMenus({}, sysemId).then(res => {
        that.leftMenuDatas = createRouterAndMenuList(res.data.data);
      });
    },
    collopseOperation: function () {
      this.isCollapse = !this.isCollapse;
    },
    closeTab: function (data) {
      this.$store.dispatch("clearNavBar", data);
      this.$store.dispatch("clearCache", data.componentName);
    },
    redirect: function (item) {
      this.$router.push({path: item.path});
    },
    changeTab: function (data) {
      this.$store.dispatch("changeTab", data);
    }
  },
  computed: {
    ...mapGetters(["getNavData", "getViewCache", "getPermissionMenus"])
  },
  watch: {
    isCollapse: function (val) {
      let that = this;
      setTimeout(function () {
        that.outerIsCollapse = val;
      }, 200);
    }
  }
}
</script>

<style lang = "scss" scoped>
.el-header {
  box-shadow: 0px 10px 5px #f7f7f7;
}

#nprogress .bar {
  background: red !important;
}

.el-menu--collapse {
  width: 100%;
  height: 100%;
}

.el-menu-item {
  height: 35px;
}

.nav_area {
  width: 100%;
  display: flex;
  flex-direction: row;

  .nav_left {
    width: 200px;
  }

  .nav-title {
    height: 35px;
    background: #e3e9f2;
    margin: 7px 0px 0px 0px;
    -webkit-box-shadow: 0 2px 10px 0 rgba(75, 61, 89, 0.3);
    box-shadow: 0 2px 10px 0 rgba(75, 61, 89, 0.3);
    border-bottom: 1px solid hsla(13, 23%, 73%, 10);
    box-sizing: border-box;
  }
}

.el-header {
  -el-header-padding: 0px;
  --el-header-height: none;
}

.toolbar {
  border-bottom: #3a8ee6 solid 2px;
  float: left;
  width: 100%;
  display: flex;
  position: relative;
}


.toolItem {
  float: left;
  display: flex;
  height: 35px;
  margin-top: 5px;
  cursor: pointer;
}

.toolItem span {
  font-size: 14px;
}

.dot {
  width: 10px;
  height: 10px;
  background-color: #409eff;
  border-radius: 50%;
  display: inline-block;
  margin-right: 5px;
}

.star-horse-left::-webkit-scrollbar {
  display: none;
  width: 3px;
  height: 3px;
}

.show-scroll-bar::-webkit-scrollbar {
  display: block;
}

.hide-scroll-bar::-webkit-scrollbar {
  display: none;
}

//.el-aside {
//  --el-aside-width: none;
//  max-height: calc(100vh - 125px);
//  overflow-x: hidden;
//  /*box-shadow: 8px 8px 40px 0 rgba(35, 40, 67, .16);*/
//}

//.router-link-exact-active,
//.active {
//  color: #2c3e50;
//  font-weight: bold;
//}


</style>
